package com.test.wxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class MapperProxy<T> implements InvocationHandler {
    // 生成某个接口的mapper
    public static <T> T newInstance(Class<T> clazz)
    {
        MapperProxy<T> proxy = new MapperProxy<>();
        // 动态代理
        return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class[] { clazz }, proxy);
    }

    // 调用mapper方法时实际执行的内容
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
    {
        System.out.println("invoke " + method.getName());
        return null;
    }
}
